package com.excilys.capicsoubank.validators;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.apache.commons.lang3.ObjectUtils;

import com.excilys.capicsoubank.constraints.AccountIdNotEquals;
import com.excilys.capicsoubank.form.TransferForm;

/**
 * Validator pour l'annotation AccountIdNotEquals.
 * 
 * @author "Grégory Coutant"
 * 
 */
public class AccoundIdNotEqualsValidator implements
		ConstraintValidator<AccountIdNotEquals, TransferForm> {

	@Override
	public void initialize(AccountIdNotEquals constraintAnnotation) {
	}

	@Override
	public boolean isValid(TransferForm form, ConstraintValidatorContext context) {

		Integer accountSource = form.getAccountSource();
		Integer accountDestination = form.getAccountDestination();

		if (accountSource == null || accountDestination == null)
			return true;

		return ObjectUtils.notEqual(accountSource, accountDestination);
	}
}
